package top.college.jjb;

import java.awt.BorderLayout;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.swing.BoxLayout;


import top.college.dao.JDBC_ConnClose;
import top.college.model.StudentVO;
import java.awt.GridLayout;
import javax.swing.SwingConstants;
// 학생 정보 수정
public class studentupd extends JPanel {
	private JTextField tf1;
	private JTextField tf2;
	private JTextField tf3;
	private JTextField tf4;
	private static Connection conn;
	private static PreparedStatement pstmt;
	private static ResultSet rs;
	private JTextField tf5;
	
	public studentupd() {
		setLayout(new BorderLayout(0, 0));
		uptop();
		updown();
		
	}


private void uptop(){
	new JPanel();
	
	JPanel infop = new JPanel();
	add(infop, BorderLayout.NORTH);
	
	JLabel infolab = new JLabel("학생 정보 수정");
	infop.add(infolab);
}
private void updown(){
	
	JPanel panel = new JPanel();
	panel.setPreferredSize(new Dimension(100, 10));
	add(panel, BorderLayout.WEST);
	panel.setLayout(new GridLayout(0, 1, 0, 0));
	
	JLabel label = new JLabel("이름");
	label.setHorizontalTextPosition(SwingConstants.CENTER);
	label.setHorizontalAlignment(SwingConstants.CENTER);
	label.setAlignmentY(1.0f);
	panel.add(label);
	
	JLabel label_1 = new JLabel("패스워드");
	label_1.setHorizontalTextPosition(SwingConstants.CENTER);
	label_1.setHorizontalAlignment(SwingConstants.CENTER);
	label_1.setAlignmentY(1.0f);
	panel.add(label_1);
	
	JLabel label_2 = new JLabel("전화번호");
	label_2.setHorizontalTextPosition(SwingConstants.CENTER);
	label_2.setHorizontalAlignment(SwingConstants.CENTER);
	panel.add(label_2);
	
	JLabel lblNewLabel_1 = new JLabel("주소");
	lblNewLabel_1.setHorizontalTextPosition(SwingConstants.CENTER);
	lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
	panel.add(lblNewLabel_1);
	
	JPanel panel_1 = new JPanel();
	add(panel_1, BorderLayout.EAST);
	
	JPanel panel_2 = new JPanel();
	add(panel_2, BorderLayout.CENTER);
	panel_2.setLayout(new GridLayout(0, 1, 0, 0));
	
	tf1 = new JTextField();
	tf1.setColumns(10);
	panel_2.add(tf1);
	
	tf2 = new JTextField();
	tf2.setColumns(10);
	panel_2.add(tf2);
	
	tf3 = new JTextField();
	tf3.setColumns(10);
	panel_2.add(tf3);
	
	tf4 = new JTextField();
	panel_2.add(tf4);
	tf4.setColumns(10);
	
	tf5 = new JTextField();
	panel_2.add(tf5);
	tf5.setColumns(10);
	
	JPanel panel_3 = new JPanel();
	add(panel_3, BorderLayout.SOUTH);
	
	JButton btnNewButton = new JButton("수정");
	btnNewButton.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			StudentVO sv = new StudentVO();
			sv.setStd_name(tf1.getText());
			sv.setStd_pw(tf2.getText());
			sv.setStd_tel(tf3.getText());
			sv.setStd_addr(tf4.getText());
			sv.setStd_no(tf5.getText());
			
			try{
				conn = JDBC_ConnClose.openDataBase();
				pstmt = conn.prepareStatement(JDBC_SQL_1.StudentUpdateSQL);
				pstmt.setString( 1, sv.getStd_name());
				pstmt.setString( 2, sv.getStd_pw());
				pstmt.setString( 3, sv.getStd_tel());
				pstmt.setString( 4, sv.getStd_addr());
				pstmt.setString( 5, sv.getStd_no());
				pstmt.executeUpdate();
				JOptionPane.showMessageDialog(null, "수정완료");
			}catch(Exception ex){
				ex.printStackTrace();
			}finally{
				JDBC_ConnClose.closeDataBase(conn, pstmt, rs);
			}
		}
		
	});
	panel_3.add(btnNewButton);
	
	JButton btnNewButton_1 = new JButton("확인");
	panel_3.add(btnNewButton_1);
}

}
